<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>动态规划</title>
</head>

<body>

</body>
<script>
    // 求最长公共子串
    function LCS(str1, str2) {
        // write code here
        if (!str1 || !str2) return -1;
        if (str1.length > str2.length) {
            //         两值互换
            [str1, str2] = [str2, str1];
        }
        let maxlen = 0, res = '';
        for (let i = 0; i < str1.length; i++) {
            if (str2.indexOf(str1.slice(i - maxlen, i + 1)) !== -1) {
                res = str1.slice(i - maxlen, i + 1)
                maxlen += 1
            }
        }
        return res || -1
    }


</script>

</html>